package com.dixon.worddayday.controller;

import com.dixon.worddayday.request.WeChatLoginReq;
import com.dixon.worddayday.response.BaseRes;
import com.dixon.worddayday.service.AuthService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

@RestController
@Slf4j
@RequiredArgsConstructor
public class AuthController extends BaseController {
    private final AuthService authService;

    /**
     * 微信小程序授权登录
     * @param loginReq 微信登录请求参数
     * @return JWT token
     */
    @PostMapping("/auth/login")
    public BaseRes<String> wechatLogin(@RequestBody @Valid WeChatLoginReq loginReq) throws Exception {
        return authService.login(loginReq);
    }
}
